/*
 ******************************************************************************
 *
 *       Copyright ASTRI, 2016.  All rights reserved.
 *
 *   This software is proprietary to and embodies the confidential technology
 *   of Hong Kong Applied Science and Technology Research Institute Company
 *   Limited (ASTRI).
 *   Possession, use, or copying of this software and media is authorized
 *   only pursuant to a valid written license from ASTRI or an authorized
 *   sublicensor.
 *
 * File Name:
 *   XXX.java
 *
 * Purpose:
 *   
 *   
 *   
 *
 * Project or Modules Name:
 *   
 *
 * Modules Contained:
 *   N/A
 *
 * Modification History:
 * Date(DDMMYY)  Version No Modified By  Description
 * ------------  ---------- -----------  -----------
 * 20160405       0.0.0.1    XXX     Created
 *
 ******************************************************************************
 */


package com.j.thetabk.thetas;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by user on 14/4/2016.
 */
public class ThetaSNumber {

    public static String [] numberName={
            "_shutterVolume",//number
            "_captureInterval",
            "_captureNumber"
    };

    public int value;
    public int minValue;
    public int maxValue;

    public ThetaSNumber()
    {

    }

    public void ParseNumber(int index, JSONObject jbProperties) throws JSONException {
        value=jbProperties.getInt(numberName[index]);
        if(index==2 && value<2)
            value=1;
    }

    public void ParseRange(int index, JSONObject jbProperties) throws JSONException {

        switch(index)
        {
            case 0:
                minValue=jbProperties.getInt("minShutterVolume");
                maxValue=jbProperties.getInt("maxShutterVolume");
            return;
            case 1:
                minValue=jbProperties.getInt("minInterval");
                maxValue=jbProperties.getInt("maxInterval");
                return;
            case 2:
                minValue=jbProperties.getInt("minNumber")-1;
                maxValue=jbProperties.getInt("maxNumber");
                return;
            default:
                return;
        }
    }


    public String DisplayNumber(int index)
    {
        switch(index)
        {
            case 0:
                return "Vol."+value;
            case 1:
            {
                String str = String.format("%02d", value % 60);
                if (value < 60)
                    return "00:" + str;
                return String.format("%02d", value / 60) + ":" + str;
            }
            case 2:
                return "("+value+")";
            default:
                return null;
        }

    }


    public JSONObject NumberItem(int index) throws JSONException {
        JSONObject jbtemp2=new JSONObject();
        if(index==2 && value<2)
            jbtemp2.put(numberName[index], 0);
        else
            jbtemp2.put(numberName[index], value);
        return jbtemp2;
    }

}
